/** m2settings is a GUI to configure Maven 2 settings.xml
 *
 *  Copyright (C) 2007 Regis Decamps <decamps@users.sf.net>
 *
 *  This file is part of m2settings.
 *
 *  m2settings is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Foobar is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *  or read it online http://www.gnu.org/licenses/gpl.txt
 *
 **/
/*
 * ServerBean.java
 *
 * Created on April 21, 2007, 2:13 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package info.decamps.m2settings.beans;

import info.decamps.m2settings.model.Server;
import info.decamps.m2settings.model.Settings;
import org.apache.commons.lang.StringUtils;
import org.omg.PortableInterceptor.SUCCESSFUL;

/**
 * This class represents a Server.
 * It extends Castor generated class to handle Unix permissions better.
 * Element  	Description
 * username 	The username used to authenticate.
 * password 	The password used in conjunction with the username to authenticate.
 * privateKey 	The private key location used to authenticate.
 * passphrase 	The passphrase used in conjunction with the privateKey to authenticate.
 * filePermissions 	The permissions for files when they are created.
 * directoryPermissions 	The permissions for directories when they are created.
 * configuration 	Extra configuration for the transport layer.
 * id 	No description.
 * @author regis
 */
public class MyServer{
    private Permissions filePermissions;
    private Permissions directoryPermissions;
    private Server server;
    
    public MyServer() {
        this(new Server());
        directoryPermissions.setUserExec(true);
        directoryPermissions.setGroupExec(true);
    }
    public MyServer(info.decamps.m2settings.model.Server s) {
        filePermissions=new Permissions(s.getFilePermissions());
        directoryPermissions=new Permissions(s.getDirectoryPermissions());
        server=s;
    }
    
    public boolean isFileUserRead() {
        return filePermissions.isUserRead();
    }
    public boolean isFileUserWrite() {
        return filePermissions.isUserWrite();
    }
    public boolean isFileUserExec() {
        return filePermissions.isUserExec();
    }
    public boolean isDirUserRead() {
        return directoryPermissions.isUserRead();
    }
    public boolean isDirUserWrite() {
        return directoryPermissions.isUserWrite();
    }
    public boolean isDirUserExec() {
        return directoryPermissions.isUserExec();
    }
    public boolean isFileGroupRead() {
        return filePermissions.isGroupRead();
    }
    public boolean isFileGroupWrite() {
        return filePermissions.isGroupWrite();
    }
    public boolean isFileGroupExec() {
        return filePermissions.isGroupExec();
    }
    public boolean isDirGroupRead() {
        return directoryPermissions.isGroupRead();
    }
    public boolean isDirGroupWrite() {
        return directoryPermissions.isGroupWrite();
    }
    public boolean isDirGroupExec() {
        return directoryPermissions.isGroupExec();
    }
    public boolean isFileOtherRead() {
        return filePermissions.isOtherRead();
    }
    public boolean isFileOtherWrite() {
        return filePermissions.isOtherWrite();
    }
    public boolean isFileOtherExec() {
        return filePermissions.isOtherExec();
    }
    public boolean isDirOtherRead() {
        return directoryPermissions.isOtherRead();
    }
    public boolean isDirOtherWrite() {
        return directoryPermissions.isOtherWrite();
    }
    public boolean isDirOtherExec() {
        return directoryPermissions.isOtherExec();
    }
    public Server getServer() {
        return server;
    }
    
    public String getId() {
        return server.getId();
    }
    
    public String getUsername() {
        return server.getUsername();
    }
    
    public String getPassword() {
        return server.getPassword();
    }
    
    public String getPrivatekey() {
        return server.getPrivateKey();
    }
    
    public String getPassphrase() {
        return server.getPassphrase();
    }
    
    public void setFilePermissions(Permissions filePermissions) {
        this.filePermissions=filePermissions;
        server.setFilePermissions(filePermissions.toString());
    }
    public void setDirectoryPermissions(Permissions directoryPermissions) {
        this.directoryPermissions=directoryPermissions;
        server.setDirectoryPermissions(directoryPermissions.toString());
    }
    
    public void setId(String id) {
        server.setId(id);
    }
    
    public void setUsername(String username) {
        if (StringUtils.isBlank(username))
            username=null;
        server.setUsername(username);
    }
    
    public void setPassword(String password) {
        if (StringUtils.isBlank(password))
            password=null;
        server.setPassword(password);
    }
    
    public void setPrivateKey(String privateKey) {
        if (StringUtils.isBlank(privateKey))
            privateKey=null;
        server.setPrivateKey(privateKey);
    }
    
    public void setPassphrase(String passphrase) {
        if (StringUtils.isBlank(passphrase))
            passphrase=null;
        server.setPassphrase(passphrase);
    }
    
    public void setPassword(char[] c) {
        setPassword(new String(c));
    }
    
    public void setPassphrase(char[] c) {
        setPassphrase(new String(c));
    }
    
}